---
title: Add resources dynamically with addResource
description: Click the "+room" button to dynamically add a resource
layout: demo-v4
plugins: [ interaction, timeline, resource-common, resource-timeline ]
---
<script>

  document.addEventListener('DOMContentLoaded', function() {
    var calendarEl = document.getElementById('calendar');

    var calendar = new FullCalendar.Calendar(calendarEl, {
      timeZone: 'UTC',
      plugins: [ 'interaction', 'resourceTimeline' ],
      header: {
        left: 'promptResource today prev,next',
        center: 'title',
        right: 'resourceTimelineDay,resourceTimelineWeek'
      },
      customButtons: {
        promptResource: {
          text: '+ room',
          click: function() {
            var title = prompt('Room name');
            if (title) {
              calendar.addResource({
                title: title
              });
            }
          }
        }
      },
      // editable: true,
      aspectRatio: 1.5,
      defaultView: 'resourceTimelineDay',
      resourceLabelText: 'Rooms',
      resources: '{{ site.data.demo_feed_baseurl }}/demo-resources.json?with-nesting',
      events: '{{ site.data.demo_feed_baseurl }}/demo-events.json?single-day&for-resource-timeline'
    });

    calendar.render();
  });

</script>
